package com.atguigu.principle.dependInversion.improve;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 依赖倒置原则
 * @create: 2022-01-08 15:20
 **/
public class DependInversion2 {
    public static void main(String[] args) {
        //客户端从方式一改为方式二后，客户端的调用无需改变
        Person person = new Person();
        person.receive(new Email());

        //按此方法继续调用微信
        person.receive(new WeiXin());
    }
}

/**
 * 客户端
 * 方式二: receive方法依赖IReceiver接口，receive方法被执行结果取决于入参IReceiver的实现类（引入的实现类不同则结果不同）
 */
class Person {
    public void receive(IReceiver iReceiver){
        System.out.println(iReceiver.getInfo());
    }
}

interface IReceiver {
    public String getInfo();
}

class Email implements IReceiver{
    @Override
    public String getInfo(){
        return "电子邮件信息：hello world";
    }
}
class WeiXin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信消息：hello world";
    }
}


